home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / rgip.trm < prev    next >
Text File  |  1993-09-15  |  9KB  |  372 lines

  1. /*
  2.  * $Id: rgip.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  */
  4.  
  5. /* GNUPLOT - rgip.trm Uniplex graphics metafile */
  6. /*
  7.  * Copyright (C) 1990
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   RGIP metafile
  25.  *
  26.  * AUTHORS
  27.  *   Hans Olav Eggestad
  28.  *
  29.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  30.  *
  31.  */
  32.  
  33. /*
  34.  * Original for direct RGIP Metafile output.
  35.  */
  36. /* 
  37.  * Max pixels for X and Y in one window is 10000.
  38.  */
  39.  
  40. #include <sys/types.h>
  41. #include <sys/stat.h>
  42.  
  43. #define RGIP_X_MAX 10000
  44. #define RGIP_Y_MAX 10000
  45. #define RGIP_XMAX 9900
  46. #define RGIP_YMAX 9900
  47.  
  48. #define RGIPDOTS 0
  49. #define RGIPMARK 1
  50. #define RGIPTEXT 2
  51. #define RGIPLINE 3
  52. #define RGIPPOLY 4
  53. static char *RGIP_Obj[6] = { "DOTS", "MARK", "TEXT", "LINE", "POLY" };
  54.  
  55. /* 
  56.  * RGIP fontsises range from 1 to 8 
  57.  */
  58.  
  59. #define RGIP_SC (300)
  60. #define RGIP_FONTSIZE 1
  61. #define RGIP_FACES 3
  62. #define RGIP_FSTYLES 4
  63. #define RGIP_FSIZES 8
  64. #define RGIP_HELVETICA 0
  65. #define RGIP_TIMES 1
  66. #define RGIP_COURIER 2
  67. #define RGIP_LINE_WIDTHS 8 /* future, currently invisible and visible 0
  68. and 1 */
  69. #define RGIP_LINE_TYPES 8
  70. #define RGIP_COLORS 16
  71. #define RGIP_POINT_TYPES 8
  72.  
  73.  
  74.  
  75. #define RGIP_HTIC (100)
  76. #define RGIP_VTIC (100)
  77. #define RGIP_VCHAR (RGIP_FONTSIZE*RGIP_SC) 
  78. #define RGIP_HCHAR (RGIP_VCHAR*3/7)   
  79.  
  80. static int RGIP_orgx;        /* absolute-pixel-ORIgin of graph.    */
  81. static int RGIP_orgy;
  82. static int RGIP_posx;        /* current drawing position (lines).    */
  83. static int RGIP_posy;
  84. static int RGIP_inplot;
  85. static int RGIP_xmax;        /* width of graph in pixels.        */
  86. static int RGIP_ymax;        /* height of graph in pixels.        */
  87. static int RGIP_blofs;        /* BaseLine OFfSet from bounding box.    */
  88. static int RGIP_angle = 0;    /* 0 for horizontal text, 90 for vertical */
  89. static enum JUSTIFY RGIP_justify = LEFT; /* left/center/right */
  90. static int RGIP_fface = 2;  /* Times */
  91. static int RGIP_ftype = 1; /* style roman */
  92. static int RGIP_fontsize = RGIP_FONTSIZE; /*  */
  93. static int RGIP_tcol = 7;  /* text color */
  94. static int RGIP_lsty = 1;  /* line style */
  95. static int RGIP_lcol = 7;  /* line color */
  96. static int RGIP_lwid = 1;  /* line width */
  97. static int RGIP_fsty = 1;  /* fill style */
  98. static int RGIP_fcol = 7;  /* fill color */
  99. static int RGIP_mcol = 7;  /* marker color */
  100. static int RGIP_msty = 1;  /* marker style */
  101. static int RGIP_msize = 1;  /* marker size */
  102.  
  103.  
  104. static unsigned char *RGIP_cvts();
  105.  
  106.  
  107. RGIP_init()
  108. {
  109.     RGIP_posx = RGIP_posy = 0;
  110.  
  111.     RGIP_orgx = (RGIP_X_MAX - RGIP_XMAX) / 2;
  112.     RGIP_orgy = (RGIP_Y_MAX - RGIP_YMAX) / 2;
  113.  
  114. }
  115.  
  116. RGIP_graphics()
  117. {
  118.     static int Gnr = 0;
  119.     struct stat buf;
  120.     unsigned char *p, fn[128];
  121.  
  122.     fstat(fileno(outfile),&buf);
  123.     if ( S_ISREG(buf.st_mode)) {
  124.         if (p=(unsigned char *)strchr(outstr,'X')) { /* substitute X with graphnr */
  125.         if ( ! Gnr ) { /* delete the base file */
  126.             sprintf(fn,"%s",&outstr[1]);
  127.             fn[strlen(fn)-1]='\0';
  128.             unlink(fn);
  129.         } else {
  130.                 fputs("%RI_GROUPEND\n", outfile);
  131.             fclose(outfile);
  132.         }
  133.         *p = '\0';
  134.         sprintf(fn,"%s%1d%s",&outstr[1],++Gnr,p+1);
  135.            fn[strlen(fn)-1]='\0';
  136.                 if ( (outfile = fopen(fn,"w")) == (FILE *)NULL ) {
  137.                      os_error("cannot reopen file with binary type; output unknown",
  138.                            NO_CARET);
  139.                 }
  140.         *p = 'X';  /* put back X */
  141.             }
  142.     }
  143.     fputs("%RGIP_METAFILE: 1.0a\n", outfile);
  144.     fputs("%RI_GROUPSTART\n", outfile);
  145.     fputs("%RI_GROUPSTART\n", outfile);
  146.  
  147.     /* RGIP_linetype(-1); */
  148. }
  149.  
  150. RGIP_text()
  151. {
  152. }
  153.  
  154. RGIP_linetype(lt)
  155. int lt;
  156. {
  157.     int pen, pattern;
  158.  
  159. /*  -2: axis
  160.  *  -1: border
  161.  *   0: arrow
  162.  *   1-7: graph
  163. */
  164.     if ( lt == -2 ) {
  165.     lt = 1;
  166.     RGIP_lwid = 3;
  167.     } else if ( lt == -1 ) {
  168.     lt = 5;
  169.     RGIP_lwid = 1;
  170.     } else {
  171.     RGIP_lwid = (int) (lt/RGIP_LINE_TYPES);
  172.     if ( RGIP_lwid <= 0 ) RGIP_lwid = 1;
  173.         lt  = (lt % RGIP_LINE_TYPES) + 1;
  174.     }
  175.     fputs("%RI_GROUPEND\n", outfile);
  176.     fputs("%RI_GROUPSTART\n", outfile);
  177.  
  178.     /* RGIP_lsty  = (lt == 0 || lt == 2) ? 1 : lt; */
  179.  
  180.     RGIP_lsty = lt;
  181. }
  182.  
  183.  
  184. RGIP_move(x,y)
  185.     unsigned int x,y;
  186. {
  187. /*
  188.     fputs("%RI_GROUPEND\n", outfile);
  189.     fputs("%RI_GROUPSTART\n", outfile);
  190. */
  191.     RGIP_posx = x;
  192.     RGIP_posy = y;
  193. }
  194.  
  195.  
  196. RGIP_vector(ux,uy)
  197.     unsigned int ux,uy;
  198. {
  199.     /* Create line */
  200.  
  201.     fprintf(outfile,"%1d %1d %1d %1d",
  202.         RGIP_posx + RGIP_orgx,
  203.         RGIP_posy + RGIP_orgy,
  204.         ux + RGIP_orgx,
  205.         uy + RGIP_orgy);
  206.  
  207.     fprintf(outfile," %1d %d %1d %s\n", RGIP_lwid, RGIP_lsty,
  208.         RGIP_lcol, RGIP_Obj[RGIPLINE]);
  209.  
  210.     RGIP_posx = ux;
  211.     RGIP_posy = uy;
  212.     /* RGIP_move(ux, uy); */
  213. }
  214.  
  215.  
  216. RGIP_text_angle(angle)
  217.     int angle;
  218. {
  219.     if (RGIP_angle != angle) {
  220.        RGIP_angle = angle;    /* record for later use */
  221.     }
  222.  
  223.     return(TRUE);
  224. }
  225.  
  226. RGIP_justify_text(mode)
  227.     enum JUSTIFY mode;
  228. {
  229.     RGIP_justify = mode;
  230.     return(TRUE);
  231. }
  232.  
  233. static unsigned char *
  234. RGIP_cvts(str,lcnt)
  235.     unsigned char        *str;
  236.     int *lcnt;            /* lines */
  237. {
  238.     unsigned char        *cp1;
  239.     unsigned char        *cp2;
  240.     static unsigned char    *buf = NULL;
  241.     int lc = 1;
  242.  
  243.     lc = 1;
  244.     /* Free up old buffer, if there is one, get a new one.  Since    */
  245.     /* all transformations shorten the string, get a buffer that is    */
  246.     /* the same size as the input string.                */
  247.  
  248.     if (buf != NULL)
  249.      (void) free(buf);
  250.     buf = (unsigned char *) alloc(strlen(str), "converted label string");
  251.  
  252.     /* Do the transformations. */
  253.  
  254.     cp1 = str;
  255.     cp2 = buf;
  256.     while (strlen(cp1) > 0) {
  257.        switch (*cp1) {
  258.             case  '\\' :    /* Escape sequence. */
  259.              if (*++cp1 == '\\') {
  260.                 /* Begin new line. */
  261.                 *cp2++ = '\n';
  262.                 lc++;
  263.                 break;
  264.              }
  265.         
  266.             /* Fall through to just copy next char out.    */
  267.         
  268.             default :
  269.              *cp2++ = *cp1;
  270.             break;
  271.         }
  272.        cp1++;
  273.     }
  274.  
  275.     *cp2++ = '\n';
  276.     *cp2 = '\0';
  277.     *lcnt = lc; 
  278.     return (buf);
  279. }
  280.  
  281. RGIP_put_text(x, y, str)
  282.     int x,y;                /* reference point of string */
  283.     unsigned char str[];            /* the text */
  284. {
  285.     register struct termentry *t = &term_tbl[term];
  286.     unsigned char *cvstr, *p;
  287.     int xlines;        /* lines */
  288.  
  289.     cvstr = RGIP_cvts(str,&xlines);
  290.  
  291.     x += RGIP_orgx,
  292.     y += RGIP_orgy;
  293.  
  294.     if (! RGIP_angle) {      /* horisontal */
  295.     y += (int)(t->v_char)*(xlines-2)/2;
  296.     /* y += (t->v_char)*xlines; */
  297.     y += (int)(t->v_char)/4;
  298.     } else {
  299.     x -= (int)(t->v_char)*(xlines-2)/2;
  300.     x -= (int)(t->v_char)/4;
  301.     }
  302.  
  303.     while ( p=(unsigned char *)strchr(cvstr,'\n' )) {
  304.     *p = '\0';
  305.     if (strlen(cvstr)) 
  306.             fprintf(outfile,"%1d %1d %1d  %1d (%s) %1d %1d %1d %1d %s\n",
  307.                 x,y,RGIP_justify, RGIP_angle*90, cvstr, RGIP_fface, RGIP_ftype,
  308.                 RGIP_fontsize, RGIP_tcol, RGIP_Obj[RGIPTEXT]);
  309.     cvstr = ++p;
  310.     if (RGIP_angle) {     /* vertical */
  311.         x += (t->v_char);
  312.     } else {
  313.         y -= (t->v_char);
  314.     }
  315.     }
  316. }
  317.  
  318.  
  319. RGIP_reset()
  320. {
  321.     fputs("%RI_GROUPEND\n", outfile);
  322.     fputs("%RI_GROUPEND\n", outfile);
  323. }
  324.  
  325. static void
  326. RGIP_setfont(sz)
  327.     int sz;
  328. {
  329.     RGIP_fontsize = (int) (sz);
  330.     if ( RGIP_fontsize < 1 ) RGIP_fontsize = 1;
  331.     term_tbl[term].v_char = (unsigned int)(RGIP_fontsize*RGIP_SC);
  332.     term_tbl[term].h_char = (unsigned int)(RGIP_fontsize*RGIP_SC*3/7);
  333. }
  334.  
  335. RGIP_do_point(x,y,number)
  336. int x,y;
  337. int number;
  338. {
  339.  
  340.     x += RGIP_orgx,
  341.     y += RGIP_orgy;
  342.  
  343.     if (number < 0) {        /* do dot */
  344.         fprintf(outfile,"%1d %1d %1d %s\n",
  345.                x,y,RGIP_mcol,RGIP_Obj[RGIPDOTS]);
  346.         return;
  347.     }
  348.  
  349.     RGIP_msty = (number % RGIP_POINT_TYPES) + 1;
  350.     RGIP_msize = ((int)(number / RGIP_POINT_TYPES)) + 1;
  351.  
  352.     fprintf(outfile,"%1d %1d %1d %1d %1d %s\n",
  353.                x,y,RGIP_msize, RGIP_msty, RGIP_mcol, RGIP_Obj[RGIPMARK]);
  354. }
  355.  
  356. RGIP_options()
  357. {
  358.     extern struct value *const_express();
  359.     extern double real();
  360.  
  361.     if (!END_OF_COMMAND) {
  362.         /* We have font size specified */
  363.         struct value a;
  364.         RGIP_fontsize = (int)real(const_express(&a));
  365.         if ( RGIP_fontsize < 1 ) 
  366.             RGIP_fontsize = 1;
  367.         term_tbl[term].v_char = (unsigned int)(RGIP_fontsize*RGIP_SC);
  368.         term_tbl[term].h_char = (unsigned int)(RGIP_fontsize*RGIP_SC*3/7);
  369.     }
  370.     sprintf(term_options,"%d",RGIP_fontsize);
  371. }
  372.